define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user2/index' + location.search,
                    add_url: 'user2/add',
                    edit_url: 'user2/edit',
                    del_url: 'user2/del',
                    multi_url: 'user2/multi',
                    import_url: 'user2/import',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'verify_status', title: __('Verify_status'), searchList: {"0":__('Verify_status 0'),"1":__('Verify_status 1'),"2":__('Verify_status 2'),"3":__('Verify_status 3')}, formatter: Table.api.formatter.status},
                        
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'sys_switch', title: __('Sys_switch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'adv_switch', title: __('Adv_switch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'seek_switch', title: __('Seek_switch'), table: table, formatter: Table.api.formatter.toggle},

                        {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        // {field: 'prevtime', title: __('Prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'logintime', title: __('Logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'openid', title: __('Openid'), operate: 'LIKE'},
                        // {field: 'school_id', title: __('School_id')},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1'),"2":__('Sex 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'character_ids', title: __('Character_ids'), operate: 'LIKE'},
                        {field: 'fans', title: __('Fans')},
                        {field: 'chsi_code', title: __('Chsi_code'), operate: 'LIKE'},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'school.name', title: __('School.name'), operate: 'LIKE'},
                        {field: 'character.name', title: __('Character.name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
